package com.zyc.studentstudy.utils

import android.content.Context
import android.content.res.Configuration
import android.os.Build
import android.view.WindowManager

object ScreenUtil {
    @JvmStatic
    fun isLand(): Boolean {
        return ContextHolder.getResources().configuration.orientation == Configuration.ORIENTATION_LANDSCAPE
    }

    @JvmStatic
    fun getScreenWidth(context: Context): Int {
        return getScreenWidthAndHeight(context)[0]
    }

    @JvmStatic
    fun getScreenHeight(context: Context): Int {
        return getScreenWidthAndHeight(context)[1]
    }

    @JvmStatic
    fun getScreenWidthAndHeight(context: Context): IntArray {
        val dm = context.resources.displayMetrics
        val wm = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
        if (Build.VERSION.SDK_INT >= 19) {
            wm.defaultDisplay.getRealMetrics(dm)
        } else {
            wm.defaultDisplay.getMetrics(dm)
        }
        return intArrayOf(dm.widthPixels, dm.heightPixels)
    }

    @JvmStatic
    fun getDpi(context: Context): Int {
        val dm = context.resources.displayMetrics
        val wm = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
        if (Build.VERSION.SDK_INT >= 19) {
            wm.defaultDisplay.getRealMetrics(dm)
        } else {
            wm.defaultDisplay.getMetrics(dm)
        }
        return dm.densityDpi
    }
}
